/**
 * 格式化
 * @returns
 */
export const useFormat = () => {
  /**
   * 格式化时间戳
   * @param timeStamp
   * @returns
   */
  const formatTimeStamp = (timeStamp: number) => {
    const minutes = new Date(timeStamp).getMinutes()
    const seconds = new Date(timeStamp).getSeconds()
    return `${minutes >= 10 ? minutes : `0${minutes}`}:${seconds >= 10 ? seconds : `0${seconds}`}`
  }

  /**
   * 格式化单位
   * @param number
   * @returns
   */
  const formatNumberToCh = (number: number) => {
    if (number > 100000000) {
      return Number((number / 100000000).toFixed(1)) + ' 亿'
    }

    if (number > 10000000) {
      return Number((number / 10000000).toFixed(1)) + ' 千万'
    }

    if (number > 10000) {
      return Number((number / 10000).toFixed(1)) + ' 万'
    }

    return number
  }

  /**
   * 格式年月日
   * @param timestamp
   * @returns
   */
  const formatFullTimeStamp = (timestamp: number) => {
    const year = new Date(timestamp).getFullYear()
    const month = new Date(timestamp).getMonth() + 1
    const day = new Date(timestamp).getDate()
    return `${year}-${month}-${day}`
  }

  return {
    formatTimeStamp,
    formatNumberToCh,
    formatFullTimeStamp,
  }
}
